﻿#include "coladdobjectdialog.h"
#include "ui_coladdobjectdialog.h"
#include <QSqlQuery>
int COLaddobjectDialog::AID;
COLaddobjectDialog::COLaddobjectDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::COLaddobjectDialog)
{
    ui->setupUi(this);
    showpolitics();
    ui->frame->resize(this->geometry().width(), ui->frame->height());
    ui->status->setText("添加信息状态：");
    connect(ui->cancelbtn,SIGNAL(clicked(bool)),this,SLOT(close()));
}


COLaddobjectDialog::~COLaddobjectDialog()
{
    delete ui;}

void COLaddobjectDialog::receiveApprovalID(int ID)
{AID=ID;}

void COLaddobjectDialog::on_ackbtn_clicked()
{
    if(ui->copies->text().isEmpty()||ui->unit->text().isEmpty()||ui->object->text().isEmpty()){
        ui->status->setText("添加信息状态:请至少添入对象，对象单位，卷数");}
    else {
    QSqlQuery query;
    query.prepare("INSERT INTO Object(ObjectID,Objectman,Objectunit,Objectduty,politicstatus,copies,ApprovalID)"
                  "VALUES(:ObjectID,:Objectman,:Objectunit,:Objectduty,:politicstatus,:copies,:ApprovalID)");
    query.bindValue(":Objectman",ui->object->text());
    query.bindValue(":Objectunit",ui->unit->text());
    query.bindValue(":Objectduty",ui->duty->text());
    query.bindValue(":politicstatus",ui->politic->currentText());
    query.bindValue(":copies",ui->copies->text());
    query.bindValue(":ApprovalID",AID);
    bool ok=query.exec();
    if(ok)
    {ui->status->setText("添加信息状态:添加成功");
            this->close();}
    else{ui->status->setText("添加信息状态:添加失败");}
}
}

void COLaddobjectDialog::showpolitics()
{
    ui->politic->addItem("");
    QString judge=QString("select Politic from ZZB.PoliticCode ");
    QSqlQuery query;
    query.exec(judge);
    while(query.next())
    {
        QString z=query.value(0).toString();
        ui->politic->addItem(z);
}}
